package com.luo.chengrui.module.sa.enums;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public enum GlobalStatusEnum {
    ENABLED(0, "打开"),
    DISABLED(1, "关闭");


    private Integer id;
    private String name;

    GlobalStatusEnum(Integer code, String name) {
        this.id = code;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static GlobalStatusEnum getByCode(Integer id) {
        Optional<GlobalStatusEnum> optional = Arrays.stream(GlobalStatusEnum.values()).filter(item -> Objects.equals(id, item.id)).findFirst();
        if (optional.isPresent()) {
            return optional.get();
        }

        throw new RuntimeException(String.format("编码%s存在枚举【GlobalStatusEnum】中不存在", id));
    }
}
